package com.lanchetech.user.controller;

import com.lanchetech.bean.dto.AppointmentHourDTO;
import com.lanchetech.bean.request.*;
import com.lanchetech.bean.response.*;
import com.lanchetech.bean.vo.*;
import com.lanchetech.common.exception.ResultCodeException;
import com.lanchetech.entity.*;
import com.lanchetech.user.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "商品接口", tags = "商品接口(开放接口)")
@RequestMapping("/api/product")
@RestController
public class ProductController {

    @Autowired
    ProductService productService;

    @ApiOperation("获取限时优惠活动和活动的spu商品列表")
    @PostMapping("/getFlashSaleActivity")
    public ResultData<FlashSaleVO> getFlashSaleActivity(@RequestBody PageReq req, @AuthenticationPrincipal User user) {
        return productService.getFlashSaleActivity(req, user);
    }

    @ApiOperation("获取套餐商品列表")
    @PostMapping("/getPackagePage")
    public ResultData<BasePageResp<Packages>> getPackagePage(@RequestBody PageReq req) {
        return productService.getPackagePage(req);
    }

    @ApiOperation("获取套餐详情")
    @GetMapping("/getPackageDetail")
    public ResultData<PackageResp> getPackageDetail(@RequestParam("id") Long id) {
        return productService.getPackageDetail(id);
    }

    @ApiOperation("获取商品SPU详情")
    @PostMapping("/getProductDetail")
    public BaseResp getProductDetail(@RequestBody ProductReq req, @AuthenticationPrincipal User user) {
        BaseResp baseResp = new BaseResp();
        try {
            return productService.getProductDetail(req, user);
        } catch (ResultCodeException e) {
            baseResp.setResultCode(e.getResultCode());
        }
        return baseResp;
    }

    @ApiOperation("获取商品SPU详情二级页")
    @PostMapping("/getProductDetail/TwoStage")
    public ResultData<BasePageResp<SpuResp>> getProductDetailTwoStage(@RequestBody SpuPageReq req, @AuthenticationPrincipal User user) {
        return productService.getProductDetailTwoStage(req, user);
    }

    @ApiOperation("获取商家SPU指定日期预约列表")
    @PostMapping("/getSpuAppointmentByDate")
    public ResultData<List<AppointmentHourDTO>> getSpuAppointmentByDate(@RequestBody PageReq req) {
        return productService.getSpuAppointmentByDate(req);
    }

    @ApiOperation("获取商品SPU信息")
    @GetMapping("/getSpu")
    public ResultData<Spu> getSpu(@RequestParam("id") Long id) {
        return productService.getSpu(id);
    }

    @ApiOperation("获取商品SKU列表")
    @PostMapping("/getSkuList")
    public BaseResp getSkuList(@RequestBody ProductReq req,
                               @AuthenticationPrincipal User user) {
        BaseResp baseResp = new BaseResp();
        try {
            return productService.getSkuList(req,user);
        } catch (ResultCodeException e) {
            baseResp.setResultCode(e.getResultCode());
            return baseResp;
        }
    }

    @ApiOperation("获取商品自然属性列表")
    @GetMapping("/getAttributeList")
    public ResultData<List<SpuAttributeVO>> getAttributeList(@RequestParam("spuId") Long spuId) {
        return productService.getAttributeList(spuId);
    }

    @ApiOperation("获取商品列表")
    @PostMapping("/getSpuPage")
    public ResultData<BasePageResp<SpuResp>> getSpuPage(@RequestBody SpuPageReq req, @AuthenticationPrincipal User user) {
        return productService.getSpuPage(req, user);
    }

    @ApiOperation("猜你喜欢")
    @PostMapping("/like")
    public ResultData<BasePageResp<SpuResp>> like(@RequestBody SpuPageReq req, @AuthenticationPrincipal User user) {
        return productService.like(req, user);
    }

    @ApiOperation("获取商家商品分页")
    @PostMapping("/getShopSpuPage")
    public ResultData<BasePageResp<ShopSpuVO>> getShopSpuPage(@RequestBody SpuPageReq req) {
        return productService.getShopSpuPage(req);
    }

    @ApiOperation("获取商品评论分页")
    @PostMapping("/getCommentPage")
    public ResultData<BasePageResp<OrderCommentResp>> getCommentPage(@RequestBody PageReq req) {
        return productService.getCommentPage(req);
    }

    @ApiOperation("添加足迹，获取收藏，获取购物车数量")
    @GetMapping("/getTraceCollectionShoppingCart")
    public ResultData<CollectionShoppingCartVO> getTraceCollectionShoppingCart(@AuthenticationPrincipal User user, @RequestParam("spuId") Long spuId) {
        return productService.getTraceCollectionShoppingCart(user, spuId);
    }

    @ApiOperation("生成商品分享图片")
    @GetMapping("/createProductShareQrcode")
    public ResultData<String> createProductShareQrcode(@AuthenticationPrincipal User user,
                                                       @RequestParam("spuId") Long spuId,
                                                       @RequestParam(value = "activityType", required = false) String activityType,
                                                       @RequestParam(value = "activityId", required = false) Long activityId,
                                                       @RequestParam(value = "share", defaultValue = "false", required = false) boolean share) {
        return productService.createProductShareQrcode(user, spuId, activityType, activityId, share);
    }

    @ApiOperation("获取专区商品详情")
    @GetMapping("/getZoneSpuDetail")
    public ResultData<ZoneVO> getZoneSpuDetail(@RequestParam("zoneId") Long zoneId) {
        return productService.getZoneSpuDetail(zoneId);
    }

    @ApiOperation("编辑选品申请")
    @PostMapping("/editSelectionApply")
    public ResultData<Long> editSelectionApply(@RequestBody SelectionApply req) {
        return productService.editSelectionApply(req);
    }

    @ApiOperation("获取选品申请详情")
    @GetMapping("/getSelectionApplyDetail")
    public ResultData<SelectionApplyVO> getSelectionApplyDetail(@AuthenticationPrincipal User user) {
        return productService.getSelectionApplyDetail(user);
    }

    @ApiOperation("删除选品申请")
    @GetMapping("/deleteSelectionApply")
    public BaseResp deleteSelectionApply(@RequestParam("id") Long id) {
        return productService.deleteSelectionApply(id);
    }

    @ApiOperation("编辑选品")
    @PostMapping("/editSelection")
    public BaseResp editSelection(@RequestBody SelectionReq req) {
        return productService.editSelection(req);
    }

    @ApiOperation("添加选品")
    @PostMapping("/uploadSelection")
    public BaseResp uploadSelection(@RequestBody SelectionBatchReq req) {
        return productService.uploadSelection(req);
    }

    @ApiOperation("删除选品")
    @GetMapping("/deleteSelection")
    public BaseResp deleteSelection(@RequestParam("id") Long id) {
        return productService.deleteSelection(id);
    }

    @ApiOperation("获取我的选品申请分页")
    @PostMapping("/getMySelectionApplyPage")
    public ResultData<BasePageResp<SelectionApplyVO>> getMySelectionApplyPage(@RequestBody PageReq req, @AuthenticationPrincipal User user) {
        return productService.getMySelectionApplyPage(req, user);
    }

    @ApiOperation("获取选品详情")
    @GetMapping("/getSelectionDetail")
    public ResultData<Selection> getSelectionDetail(@RequestParam("id") Long id) {
        return productService.getSelectionDetail(id);
    }

    @ApiOperation("获取我的选品分页")
    @PostMapping("/getMySelectionPage")
    public ResultData<BasePageResp<Selection>> getMySelectionPage(@RequestBody PageReq req) {
        return productService.getMySelectionPage(req);
    }

    @ApiOperation("获取我的选品列表")
    @GetMapping("/getMySelectionList")
    public ResultData<List<Selection>> getMySelectionList(@RequestParam("selectionApplyId") Long id) {
        return productService.getMySelectionList(id);
    }

    @ApiOperation("获取秒杀商品分页")
    @PostMapping("/getFlashSpuPage")
    public ResultData<BasePageResp<FlashSaleSpuItemVO>> getFlashSpuPage(@RequestBody PageReq req, @AuthenticationPrincipal User user) {
        return productService.getFlashSpuPage(req, user);
    }

    @ApiOperation("获取Boss圈排行榜")
    @PostMapping("/getBossRanking")
    public ResultData<BasePageResp<BossRankingVo>> getBossRanking(@RequestBody PageReq req) {
        return productService.getBossRanking(req);
    }

}
